<?php
namespace Shared\Main;

use Doctrine\ORM\Mapping as ORM;

/**
 * Description of MetaData
 *
 * @author nofear
 */

/**
 * @ORM\Entity
 * @ORM\Table(name="metadatas")
 */
class Metadata {
    
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    private $id;
    
    /**
     * @ORM\ManyToMany(targetEntity="Tag")
     * @ORM\JoinTable(
     *      name="metadata_tags",
     *      joinColumns={@ORM\JoinColumn(name="metadataId", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="tagId", referencedColumnName="id")}
     * )
     */
    private $tags;
    
    /**
     * @ORM\Column(type="text")
     */
    private $description;
    
    public function __construct() {
        $this->tags = new \Doctrine\Common\Collections\ArrayCollection();
    }
    
    public function getId() {
        return $this->id;
    }

    public function getTags() {
        return $this->tags;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function setTags($tags) {
        $this->tags = $tags;
    }
    
    public function getDescription() {
        return $this->description;
    }

    public function setDescription($description) {
        $this->description = $description;
    }
    
    public function tagsToStr() {
        $str = '';
        
        if (count($this->tags)) {
            foreach($this->tags as $index => $Tag) {
                $str .= $Tag->getName();
                
                if (($index + 1) < count($this->tags)) {
                    $str .= ', ';
                }
            }
        }
        
        return $str;
    }
}
